import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const asyncRoutes = []
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '数据概览', icon: 'mianxingyibiaopan' }
      }
    ]
  },
  {
    path: '/base',
    component: Layout,
    name: 'Base',
    meta: { title: '后台管理', icon: 'ren' },
    children: [
      {
        path: 'users',
        name: 'BaseUsers',
        component: () => import('@/views/users/userinfo'),
        meta: { title: '用户', icon: 'yingyong' }
      },
      {
        path: 'menus',
        name: 'menus',
        component: () => import('@/views/base/menus'),
        meta: { title: '菜单', icon: 'yingyong' }
      }
      // {
      //   path: 'permissions',
      //   name: 'permissions',
      //   component: () => import('@/views/dashboard/index'),
      //   meta: { title: '权限', icon: 'yingyong' }
      // },
      // {
      //   path: 'logs',
      //   name: 'baseLogs',
      //   component: () => import('@/views/dashboard/index'),
      //   meta: { title: '日志', icon: 'yingyong' }
      // }
    ]
  },

  {
    path: '/companys',
    component: Layout,
    children: [
      {
        path: 'list',
        name: 'companysList',
        component: () => import('@/views/companys'),
        meta: { title: '企业管理', icon: 'renkou' }
      }
    ]
  },
  {
    path: 'xueke',
    component: Layout,
    name: 'Example',
    meta: { title: '题库管理', icon: 'wenjian' },
    children: [
      {
        path: '/xueke/table',
        name: 'Table',
        component: () => import('@/views/questions/list'),
        meta: { title: '基础题库', icon: 'yingyong' }
      },
      {
        path: '/questions/choice',
        name: 'choice',
        component: () => import('@/views/questions/choice'),
        meta: { title: '精选题库', icon: 'yingyong' }
      },
      {
        path: '/questions/new',
        name: 'new',
        component: () => import('@/views/questions/new'),
        meta: { title: '试题录入', icon: 'yingyong' }
      },
      {
        path: '/questions/new/:id',
        name: 'News',
        hidden: true,
        component: () => import('@/views/questions/new'),
        meta: { title: '试题录入修改', icon: 'tree' },
        props: true
      },
      {
        path: '/questions/randoms',
        name: 'randoms',
        component: () => import('@/views/questions/randoms'),
        meta: { title: '组题列表', icon: 'yingyong' }
      }
    ]
  },
  {
    path: '/subjects',
    component: Layout,
    name: 'subjects',
    meta: { title: '学科管理', icon: 'rili' },
    children: [
      {
        path: 'list',
        name: 'list',
        component: () => import('@/views/subjects/list'),
        meta: { title: '学科', icon: 'yingyong' }
      },
      {
        path: 'directorys',
        name: 'directorys',
        component: () => import('@/views/subjects/directorys'),
        meta: { title: '目录', icon: 'yingyong' }
      },
      {
        path: '/subjects/directorys/:id',
        name: 'editDirectorys',
        component: () => import('@/views/subjects/directorys'),
        // 开启props传参，对应组件可用props接收所定义的参数值，
        // 该路由定义的参数为articleId
        props: true
      },
      {
        path: 'tags',
        name: 'tags',
        component: () => import('@/views/subjects/tags'),
        meta: { title: '标签', icon: 'yingyong' }
      },
      {
        path: '/subjects/tags/:id',
        name: 'eTags',
        component: () => import('@/views/subjects/tags'),
        // meta: { title: '标签', icon: 'tree' },
        props: true
      }
    ]
  },

  {
    path: '/articles',
    component: Layout,
    children: [
      {
        path: 'list',
        name: 'articlesList',
        component: () => import('@/views/articles'),
        meta: { title: '面试技巧', icon: 'yingyong' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]
const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
